/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DAL.Login;
import DTO.dNhanvien;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author nvc11190
 */
public class bLogin {
    private Login lg;
    private ResultSet rs;
    private dNhanvien dnv;
    private int flag;
    private int count;
    public String name;
    public bLogin()
    {
        this.lg = new Login();
    }
    public void testLogin(String user, String pass) throws SQLException
    {
        this.rs=lg.TestLogin(user);
        
        while (rs.next())
        {
             count=count+1;
             this.dnv = new dNhanvien();
         
           dnv.setMa_nv(rs.getString(1));
           dnv.setMa_phong(rs.getString(2));
           dnv.setTen(rs.getString(3));
           dnv.setNgay_sinh(rs.getString(4));
           dnv.setDia_chi(rs.getString(5));
           dnv.setDt(rs.getString(6));
           dnv.setQue_quan(rs.getString(7));
           dnv.setChuc_vu(rs.getString(8));
           dnv.setUsername(rs.getString(9));
           dnv.setPass(rs.getString(10));
         
           if (!dnv.getPass().equals(pass))
              {
           
            this.flag=2;
              }
            else
             {
            
            this.flag=3;
            JOptionPane.showMessageDialog(null, "Đăng nhập thành công!");
             }
        }
        
        if(count==0)
            {
                this.flag=1;
                
            }
       
        
      
    }
    public int flags()
    {
        if(this.flag==3)
        {
            if(dnv.getChuc_vu().equals("Admin"))
                this.flag=4;
            if(dnv.getChuc_vu().equals("NVCuocGoi"))
                this.flag=5;
            if(dnv.getChuc_vu().equals("TPKyThuat"))
                this.flag=6;
            if(dnv.getChuc_vu().equals("NVKyThuat"))
                this.flag=7;
            if(dnv.getChuc_vu().equals("TPKinhDoanh"))
                this.flag=8;
            if(dnv.getChuc_vu().equals("NVKinhDoanh"))
                this.flag=9;
        }
        return this.flag;
        
    }

              public String names()
              {
                  if((flag==3)||(flag==4)||(flag==5)||(flag==6)||(flag==7)||(flag==8)||(flag==9))
                    {
                        name=dnv.getTen();
                        return name;
                    }
                  
                  
                   return null;
                  
              }
             public String manv()
              {
                  if((flag==3)||(flag==4)||(flag==5)||(flag==6)||(flag==7)||(flag==8)||(flag==9))
                    {
                        name=dnv.getMa_nv();
                        return name;
                    }
                  
                  
                   return null;
                  
              }
}